import { ref, computed } from "vue";
import { useEquip } from "@/stores/useEquip";
import { equip1 } from "@/configs/equip";
import { deepClone } from "@/utils/conversion";
import default_equip_info from "@/assets/data/default_equip_info.json";
import { datetimeFormat } from "@/utils/date";

const currentUnid = ref(equip1.unid);
const detailV2 = computed(() => {
    const equipStore = useEquip();
    return equipStore.equipsInfo.find((v) => v.fUNID == currentUnid.value) || (deepClone(default_equip_info) as Equip.EquipInfo);
});
const setCurrentUnid = (id: string) => {
    const equipStore = useEquip();
    currentUnid.value = id;
    if (detailV2.value.histories.length < 10) equipStore.syncEquipHistory({ funid: currentUnid.value, second: 3600, begintime: datetimeFormat(Date.now() - 86400000, "Y-M-D") + " 00:00:00", endtime: datetimeFormat(Date.now()) });
};
export const useCurrentEquip = () => ({
    currentUnid,
    detailV2,
    setCurrentUnid,
});
